/*
 * Copyright (c) 2024 Black Sesame Technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdlib.h>
#include "dal/utils.h"

static void* _default_allocate(size_t size)
{
    return malloc(size);
}

static void _default_deallocate(void* pointer)
{
    free(pointer);
}

static void* _default_reallocate(void* pointer, size_t size)
{
    return realloc(pointer, size);
}

static void* _default_zero_allocate(size_t number_of_elements, size_t size_of_element)
{
    return calloc(number_of_elements, size_of_element);
}

dal_utils_allocator_t dal_utils_get_allocator()
{
    static dal_utils_allocator_t default_allocator = {
        .allocate = _default_allocate,
        .deallocate = _default_deallocate,
        .reallocate = _default_reallocate,
        .zero_allocate = _default_zero_allocate,
    };
    return default_allocator;
}